import { SHOP_TYPE } from '../common/constants';

// 店铺
module.exports = app => {
    const DataTypes = app.Sequelize;
    const Model = app.model.define('shop', {
        id: {
            type: DataTypes.INTEGER(11).UNSIGNED,
            allowNull: false,
            primaryKey: true,
            autoIncrement: true,
        },
        uuid: {
            type: DataTypes.STRING(60),
            allowNull: false,
            comment: "uuid，唯一标示，比起ID更安全"
        },
        name: {
            type: DataTypes.STRING(60),
            allowNull: false,
            comment: "店铺名称"
        },
        domain: {
            type: DataTypes.STRING(128),
            allowNull: true,
            comment: "网站域名"
        },
        phone: {
            type: DataTypes.STRING(128),
            allowNull: true,
            comment: "联系方式"
        },
        address: {
            type: DataTypes.STRING(128),
            allowNull: true,
            comment: "商铺地址"
        },
        about: {
            type: DataTypes.TEXT,
            allowNull: true,
            comment: "关于我们"
        },
        appid: {
            type: DataTypes.STRING(128),
            allowNull: true,
            comment: "微信appid"
        },
        secret: {
            type: DataTypes.STRING(128),
            allowNull: true,
            comment: "微信secret"
        },
        mchid: {
            type: DataTypes.STRING(128),
            allowNull: true,
            comment: "商户号"
        },
        partner_key: {
            type: DataTypes.STRING(3000),
            allowNull: true,
            comment: "微信支付API密钥"
        },
        pay_tips: {
            type: DataTypes.STRING(128),
            allowNull: true,
            comment: "支付提示"
        },
        type: {
            type: DataTypes.STRING(128),
            allowNull: false,
            defaultValue: '餐饮',
            enum: SHOP_TYPE,
            comment: "店铺类型，CATERING->餐饮，OTHER->其它"
        },
        fei_user: {
            type: DataTypes.STRING(128),
            allowNull: true,
            comment: "飞蛾打印机用户名"
        },
        fei_ukey: {
            type: DataTypes.STRING(128),
            allowNull: true,
            comment: "飞蛾打印机用户KEY"
        },
        fei_sn: {
            type: DataTypes.STRING(128),
            allowNull: true,
            comment: "飞蛾打印机编号"
        },
        tableware: {
            type: DataTypes.INTEGER(11),
            allowNull: true,
            defaultValue: 0,
            comment: '餐具/人'
        },
        pack: {
            type: DataTypes.INTEGER(11),
            allowNull: true,
            defaultValue: 0,
            comment: '打包费/个'
        },
        all_price: {
            type: DataTypes.INTEGER(11),
            allowNull: true,
            defaultValue: 0,
            comment: '购买商品的总价'
        },
		user_id: {
			type: DataTypes.STRING(50),
			allowNull: true,
		},
        status: {
            type: DataTypes.INTEGER(2).UNSIGNED,
            allowNull: true,
            defaultValue: 0,
            comment: '店铺状态，0-> 停用，1-> 启用'
        },
        template_id: {
            type: DataTypes.INTEGER(11),
            allowNull: true,
            defaultValue: 1,
            comment: '小程序模板ID'
        },
        logo: {
            type: DataTypes.STRING(128),
            allowNull: true,
            comment: "LOGO"
        },
        is_delete: {
            type: DataTypes.INTEGER(1).UNSIGNED,
            allowNull: false,
            defaultValue: '0',
            comment: '是否删除，0->存在，1->删除'
        },
    }, {
        tableName: 'shop',
        comment: "店铺表"
    });

    Model.sync({ alter: true });
    
    return Model;
};
